package com.yyfax.account.common.util;

import com.yyfax.account.common.enums.TableNameEnum;

/**
 * 分表工具类
 * 
 * @author maojian
 * @date 2017-09-02 14:17:02
 * @since v1.0.0
 */
public class TableSegmentUtils {

	/**
	 * 返回表的segment
	 * 
	 * @author maojian
	 * @date 2017-09-02 14:16:47
	 * @since v1.0.0
	 * @param table TableNameEnum
	 * @param balanceId table id
	 * @return table segment
	 */
	public static String getTableSegment(TableNameEnum table, String balanceId) {
		String hashCode = String.valueOf(balanceId.hashCode());
		long segment = Math.abs(Long.parseLong(hashCode)) % table.getSegment();
		return segment + "";
	}

}
